<%@ page import="com.mysql.cj.jdbc.ConnectionGroupManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="entity.other.File" %>
<%@ page import="org.apache.commons.dbutils.handlers.BeanListHandler" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.commons.dbutils.*" %>
<%--
  Created by IntelliJ IDEA.
  User: 李学健
  Date: 2024/4/6
  Time: 11:57
  To change this template use File | Settings | File Templates.
--%>

<%--确保返回上一级--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<h1 style="color: #3880c2">
    <a href="index.jsp" style="color: crimson">返回主页面</a>
</h1>
<center>
    <%
        request.setCharacterEncoding("UTF-8");
        int userId = Integer.parseInt(session.getAttribute("userId").toString());
        //先声明fileList,全局变量
        List<File> myFile;
        try {
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai", "root", "123456");
            QueryRunner queryRunner = new QueryRunner();
            //解决字段映射问题
            BasicRowProcessor basicRowProcessor = new BasicRowProcessor(new GenerousBeanProcessor());

            myFile = queryRunner.query(connection, "select * from file where user_id= " + userId, new BeanListHandler<File>(File.class, basicRowProcessor));
            connection.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        for (File file : myFile) {
            out.write("<a href=\"DownloadServlet?filePath=" + file.getFilePath() + "\">" + file.getFileName()
                    + "</a> 上传时间: " + file.getUpTime() + "下载量:" + file.getDownload());
            if (file.getPower() == 0)
                out.write("    <a style=\"color: green\">" + "私有文件" + "</a>");
            else
                out.write("    <a style=\"color: #5eda56\">" + "公开文件" + "</a>");
            out.write("<br>");
        }

    %>

    <%
        //带着power回到上一个页面
        int power = Integer.parseInt(session.getAttribute("power").toString());
        out.write("<a style=\"font-size: larger\" href=\"fileSystem.jsp?power=" + power + "\" >返回</a>\n");
    %>
</center>
</body>
</html>
